#define DEBUG
#include <cstdio>
#define INF 0x7fffffffffff
#define MAXN 100000

using namespace std;

long long min(long long a, long long b) {
  return a<b ? a : b;
}

long long max(long long a, long long b) {
  return a>b ? a : b;
}

class Heap {
public:
  long long a[MAXN+1];
  int pos[MAXN+1], map[MAXN+1];

  void swap(int u, int v) {
    long long temp;
    temp=a[u], a[u]=a[v], a[v]=temp;
    temp=pos[u], pos[u]=pos[v], pos[v]=temp;
    map[pos[u]]=u, map[pos[v]]=v;
  }

  void up(int o) {
    if (o>1 && a[o]<=a[o/2]) {
      swap(o, o/2);
      up(o/2);
    }
  }

  void down(int o) {
    if (((o*2<a[0] && a[o*2]<=a[o*2+1]) || (o*2==a[0])) && a[o*2]<=a[o]) {
      swap(o, o*2);
      down(o*2);
    } else if ((o*2<a[0] && a[o*2+1]<=a[o*2]) && a[o*2+1]<=a[o]) {
      swap(o, o*2+1);
      down(o*2+1);
    }
  }

  void ins(long long x, int y) {
    a[++a[0]]=x;
    pos[a[0]]=y;
    map[y]=a[0];
    up(a[0]);
  }

  void del(int x) {
    if (x) {
      map[pos[x]]=0;
      a[x]=pos[x]=0;
      swap(x, a[0]);
      a[0]--;
      down(x);
    }
  }
};

int main() {
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);

  static Heap heap;
  static long long t[MAXN+1], a[MAXN+1], f[MAXN+1];
  static int que[MAXN+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%lld %lld", t+i, a+i);
  }

  int head=1, tail=0;
  for (int i=1, j=0; i<=n; i++) {
    for (; j<i && f[j]<t[i]; j++);
    for (; head<=tail && que[head]<j; head++) {
      heap.del(heap.map[que[head]]);
    }
    if (head<=tail) {
      heap.del(heap.map[que[head]]);
      heap.ins(f[j]+2*a[que[head]], que[head]);
    }
    for (; head<=tail && a[i]>=a[que[tail]]; tail--) {
      heap.del(heap.map[que[tail]]);
    }
    que[++tail]=i;
    f[i]=t[i]+2*a[que[head]];
    if (head==tail) {
      heap.ins(f[j]+2*a[que[tail]], que[tail]);
    } else {
      heap.ins(f[que[tail-1]]+2*a[que[tail]], que[tail]);
    }
    if (j!=i) {
      f[i]=min(f[i], heap.a[1]);
    }
  }

  printf("%lld", f[n]);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
